package com.shaoshaohuo.app.ui.fragment;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Toast;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.adapter.HomeListViewAdapter;
import com.shaoshaohuo.app.adapter.MyViewPagerAdapter;
import com.shaoshaohuo.app.utils.MyListView;

import java.util.List;

/**
 * Created by Administrator on 2017/6/5.
 */

public class HomeTabFragment extends android.support.v4.app.Fragment implements AdapterView.OnItemClickListener {
    //    public static final String ARG_PAGE = "ARG_PAGE";
//    private int mPage;
    private String url;
    private View view;
    private MyListView home_fragment_listView;
    private List<String> home_fragment_data;//String 改为实体类
    private HomeListViewAdapter home_listView_adapter;

    private ViewPager home_fragment_viewPager;
    private List<ImageView> home_viewPager_picture;
    private MyViewPagerAdapter viewPagerAdapter;
    private int picture_index = 0;
    private int[] picture = new int[]{R.mipmap.backgroud, R.mipmap.logo, R.mipmap.gouwuche};

//    public static HomeTabFragment newInstance(int page) {
//        Bundle args = new Bundle();
//        args.putInt(ARG_PAGE, page);
//        HomeTabFragment pageFragment = new HomeTabFragment();
//        pageFragment.setArguments(args);
//        return pageFragment;
//    }

    public HomeTabFragment() {

    }

    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        mPage = getArguments().getInt(ARG_PAGE);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.home_fragment_page, container, false);
        url = getArguments().getString("url");
        Toast.makeText(getActivity(), url, Toast.LENGTH_SHORT).show();
//        initView();
//        RequestData();
//        decideBanner();
//        getData();//假数据
//        bindAdapter();
////        initTimer();
//        initListener();
        return view;
    }

    private void initListener() {
        home_fragment_listView.setOnItemClickListener(this);
    }

    private void initTimer() {
//        new Timer().schedule(new TimerTask() {
//            @Override
//            public void run() {
//
//                if (picture_index < picture.length) {
//                    picture_index++;
//                } else {
//                    picture_index = 0;
//                }
//                home_fragment_viewPager.setCurrentItem(picture_index);
//            }
//        }, 1000, 1000);
    }

    private void decideBanner() {
//        if (url.equals("1")) {
//            home_fragment_viewPager.setVisibility(View.VISIBLE);
//        } else {
//            home_fragment_viewPager.setVisibility(View.GONE);
//        }
    }

//    private void getData() {
//        ImageView imageView;
//        for (int i = 0; i < 10; i++) {
//            home_fragment_data.add(i + "元/斤");
//        }
//        for (int j = 0; j < picture.length; j++) {
//            imageView = new ImageView(getActivity());
//            imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//            imageView.setImageResource(picture[j]);
//            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//            home_viewPager_picture.add(imageView);
//        }
//
//    }

    //网络请求
//    private void RequestData() {
//        Map<String, String> map = RequestParam.getHeaderParams();
//        Okhttputils.Instanse(getActivity()).getnet(map, getActivity(), "地址", new Okhttputils.OkutListener() {
//            @Override
//            public void error(Call call, IOException e) {
//
//            }
//
//            @Override
//            public void suseff(Call call, Response response, Object o) {
//
//            }
//        }, Object.class);
//    }

    private void bindAdapter() {
//        home_fragment_listView.setAdapter(home_listView_adapter);
//        home_fragment_viewPager.setAdapter(viewPagerAdapter);
    }

    private void initView() {
//        home_fragment_listView = (MyListView) view.findViewById(R.id.home_fragment_listView);
//        home_fragment_data = new ArrayList<>();
////        home_listView_adapter = new HomeListViewAdapter(getActivity(), );
//
////        home_fragment_viewPager = (ViewPager) view.findViewById(R.id.home_fragment_viewPager);
//        home_viewPager_picture = new ArrayList<>();
//        viewPagerAdapter = new MyViewPagerAdapter(getActivity(), home_viewPager_picture);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(getActivity(), "跳转", Toast.LENGTH_SHORT).show();
//        Intent intent = new Intent();
//        Bundle bundle = new Bundle();
//        startActivity(intent);
    }
}
